package com.ThreadStudy.StudyDemo;


/*
* 描述:龟兔争霸
* 这个例子是多线程争抢,它们为了争夺最终的100
*
* */


public class Winner100 implements Runnable{

    int raceLength = 100;
    String ss;
    @Override
    public void run() {
        while (raceLength>=0){

            System.out.println(Thread.currentThread().getName()+"--->拿到了第"+raceLength+"块");

            raceLength--; // 放在这,当它们拿到最终的一块时就结束了
            if(raceLength==0) {
             ss = Thread.currentThread().getName();
                System.out.println("胜利者:"+ss);
            }

        }
    }




    public static void main(String[] args) {
        Winner100 race = new Winner100();

        Thread thread = new Thread(race,"兔子");
        Thread thread1 = new Thread(race,"乌龟");

        thread.start();
        thread1.start();

    }

}
